import axios, { AxiosRequestConfig } from 'axios'

// import './__mock__'

/** 通用附件上传 */
export const apiUpload = async (
  {
    file,
    attachType,
  }: {
    /** 单个附件 */
    file: File
    /** 1.运单 2.聊天信息 3.其它 */
    attachType: number
  },
  opts?: Pick<AxiosRequestConfig, 'onUploadProgress'>,
): Promise<{ fileUrl: string; fileName: string }> => {
  const formData = new FormData()
  formData.append('file', file)
  formData.append('attachType', `${attachType}`)
  return axios.post('/tmsapi/attach/universal_upload', formData, opts).then(res => ({
    fileUrl: `${res.$data || ''}`,
    fileName: file.name,
  }))
}
